package com.sixbro.caicaitv.util;

import android.text.TextUtils;
import android.view.Gravity;
import android.widget.Toast;

import com.sixbro.caicaitv.BaseAppContext;


/**
 * Toast工具类
 */
public class ToastUtils {
    private ToastUtils() {
        /* cannot be instantiated */
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    private static Toast mToast;

    /**
     * 自定义时间显示Toast
     *
     * @param message
     * @param duration
     */
    private static void show(CharSequence message, int duration) {
        if (mToast != null) {
            mToast.cancel();
        }
        mToast = Toast.makeText(BaseAppContext.getInstance(), message, duration);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.show();
    }

    /**
     * 显示Toast
     *
     * @param message
     */
    public static void show(CharSequence message) {
        if (TextUtils.isEmpty(message)) {
            return;
        }
        if (message.length() > 15) {
            ToastUtils.show(message, Toast.LENGTH_LONG);
        } else {
            ToastUtils.show(message, Toast.LENGTH_SHORT);
        }
    }
}
